package com.lighthouse.doc.view.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.lighthouse.doc.view.domain.KnowledgeDocView;
import com.lighthouse.doc.view.service.IKnowledgeDocViewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文档-用户浏览关联Controller
 * 
 * @author ysz
 * @date 2023-06-10
 */
@RestController
@RequestMapping("/knowledge/view")
public class KnowledgeDocViewController extends BaseController
{
    @Autowired
    private IKnowledgeDocViewService knowledgeDocViewService;

    /**
     * 查询文档-用户浏览关联列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:view:list')")
    @GetMapping("/list")
    public TableDataInfo list(KnowledgeDocView knowledgeDocView)
    {
        startPage();
        List<KnowledgeDocView> list = knowledgeDocViewService.selectKnowledgeDocViewList(knowledgeDocView);
        return getDataTable(list);
    }

    /**
     * 导出文档-用户浏览关联列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:view:export')")
    @Log(title = "文档-用户浏览关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KnowledgeDocView knowledgeDocView)
    {
        List<KnowledgeDocView> list = knowledgeDocViewService.selectKnowledgeDocViewList(knowledgeDocView);
        ExcelUtil<KnowledgeDocView> util = new ExcelUtil<KnowledgeDocView>(KnowledgeDocView.class);
        util.exportExcel(response, list, "文档-用户浏览关联数据");
    }

    /**
     * 获取文档-用户浏览关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('knowledge:view:query')")
    @GetMapping(value = "/{docId}")
    public AjaxResult getInfo(@PathVariable("docId") String docId)
    {
        return success(knowledgeDocViewService.selectKnowledgeDocViewByDocId(docId));
    }

    /**
     * 新增文档-用户浏览关联
     */
    @PreAuthorize("@ss.hasPermi('knowledge:view:add')")
    @Log(title = "文档-用户浏览关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KnowledgeDocView knowledgeDocView)
    {
        return toAjax(knowledgeDocViewService.insertKnowledgeDocView(knowledgeDocView));
    }

    /**
     * 修改文档-用户浏览关联
     */
    @PreAuthorize("@ss.hasPermi('knowledge:view:edit')")
    @Log(title = "文档-用户浏览关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KnowledgeDocView knowledgeDocView)
    {
        return toAjax(knowledgeDocViewService.updateKnowledgeDocView(knowledgeDocView));
    }

    /**
     * 删除文档-用户浏览关联
     */
    @PreAuthorize("@ss.hasPermi('knowledge:view:remove')")
    @Log(title = "文档-用户浏览关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{docIds}")
    public AjaxResult remove(@PathVariable String[] docIds)
    {
        return toAjax(knowledgeDocViewService.deleteKnowledgeDocViewByDocIds(docIds));
    }
}
